package ldh.im.fxgui.component.cell;

import javafx.scene.Group;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import ldh.im.fxbase.data.pojo.ImSession;
import ldh.im.fxbase.data.pojo.ImUser;
import ldh.im.fxbase.util.ImCacheFactory;

import static ldh.im.fxgui.util.UserHeadImageUtil.getHeadImage;

public class SessionIconView extends Group {

    private ImSession imSession;

    public SessionIconView(ImSession imSession) {
        this.imSession = imSession;
        initUi();
    }

    private void initUi() {
        if (imSession.isP2p()) {
            ImageView userHeadImageView = new ImageView();
            userHeadImageView.setFitWidth(40);
            userHeadImageView.setFitHeight(40);
            String userId = imSession.getToUserId();
            ImUser toUser = ImCacheFactory.getInstance().getUser(userId);
            Image image = getHeadImage(toUser.getHeadImg());
            userHeadImageView.setImage(image);
            this.getChildren().add(userHeadImageView);
        } else {
            GroupIconView gridIconView = new GroupIconView(imSession.getImGroup());
            gridIconView.getStyleClass().add("group-icon-pane");
            this.getChildren().add(gridIconView);
        }
    }
}
